package com.china08.yxyapi.api.manage.sch.platform.xiaoben.auth;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolLessonAuth;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLessonsSchoolLessonAuthRepository;

@CrossOrigin
@RestController
public class KeChengAuthStatusListController extends YxyApiBaseController {

    @Autowired
    YxyLessonsSchoolLessonAuthRepository authRepository;

    @RequestMapping(value = "/api_yw/manage/sch/xiaoben/auth/kecheng/status/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String lessonId = reqModel.lessonId;

        List<RespModel> returnList = new ArrayList<RespModel>();

        List<YxyLessonsSchoolLessonAuth> list = authRepository.findByLessonId(lessonId);
        for (YxyLessonsSchoolLessonAuth auth : list) {
            RespModel respModel = new RespModel();
            respModel.userId = auth.getUserId();
            returnList.add(respModel);
        }
        return returnList;
    }

    public static class ReqModel extends YxyApiPageReqModel {
        public String lessonId;
    }

    public static class RespModel extends YxyApiRespModel {
        public String userId;
    }
}
